﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using SIAD.Model;
using System.ComponentModel;
using System.Windows.Media;

namespace SIAD.Controleur
{
    /// <summary>
    /// Permet de gérer le binding avec une case
    /// </summary>
    class CaseBouton : Button
    {
        #region Property
        /// <summary>
        /// La case source
        /// </summary>
        protected Case theCase;

        /// <summary>
        /// La couleur de base du background
        /// </summary>
        protected SolidColorBrush defaultBrush;
        #endregion
        #region Constructor
        /// <summary>
        /// Constructeur permettant de mettre en place le binding
        /// </summary>
        /// <param name="aCase">La case à laquelle on doit être binder</param>
        public CaseBouton(Case aCase)
        {
            this.defaultBrush = this.Background as SolidColorBrush;
            this.theCase = aCase;
            this.theCase.PropertyChanged += new PropertyChangedEventHandler(theCase_PropertyChanged);
        }

        void theCase_PropertyChanged(object sender,PropertyChangedEventArgs e)
        {
            switch (theCase.theCaseType)
            {
                case Common.CASE_TYPE.BLOCK:
                    Background = Brushes.Black;
                    break;
                case Common.CASE_TYPE.PLAYER_ONE:
                    Background = Brushes.Blue;
                    break;
                case Common.CASE_TYPE.PLAYER_TWO:
                    Background = Brushes.Blue;
                    break;
                case Common.CASE_TYPE.EMPTY:
                    Background = defaultBrush;
                    break;
                default:
                    break;
            }
        }


        #endregion
    }
}
